package com.sv.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sv.domain.User;
import com.sv.service.UserService;

@Controller
@RequestMapping(value="/user")
public class UserController {

    @Autowired
    private UserService userService;
    
    @RequestMapping(value="/edit",method= RequestMethod.GET)
    public String _new(Model model){
        
        return "user/edit";
    }
    
    @RequestMapping(method=RequestMethod.PUT)
    public String create(Model model ,User user){
        
        userService.addUser(user);
        
        User showUser = userService.findUserByUserId(1);

        model.addAttribute("user", showUser);
        return "user/show";
    }
    
    @RequestMapping(method=RequestMethod.GET)
    public String show(Model model ){
        
        User showUser = userService.findUserByUserId(1);

        model.addAttribute("user", showUser);
        return "user/show";
    }
    
    @RequestMapping(value="/load",method=RequestMethod.GET)
    public String load(Model model ){
        
        User showUser = userService.findUserByUserId(1);

        model.addAttribute("user", showUser);
        return "user/load";
    }
}
